﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movingPlatform : MonoBehaviour
{
    public float platSpeed;
    public Transform pos1;
    public Transform pos2;
    bool turnBack;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if(transform.position.x >= pos1.position.x)
        {
            turnBack = true;
        }

        if(transform.position.x <= pos2.position.x)
        {
            turnBack = false;
        }
        if(turnBack == true)
        {
            transform.position = Vector2.MoveTowards(transform.position, pos2.position, platSpeed * Time.deltaTime);
        }
        else
        {
            transform.position = Vector2.MoveTowards(transform.position, pos1.position, platSpeed * Time.deltaTime);
        }
    }
}
